package graphic.tests;

import examples.newEntityCreation.ExampleTheadBased2DEntity;
import graphic.GameView;
import graphic.render.Render2D;
import graphic.render.StandardRender;

import javax.swing.JFrame;

import model.Coordinate;
import model.entity.Entity2D;
import utils.TestMouseListener;

/**
 * Test che consente di generare velocemente un alto numero di oggetti.
 * @author Jan
 *
 */
public class RenderStressTest extends GameView{
	
	private static final long serialVersionUID = 6569555456621105645L;

	private Entity2D testMob = new ExampleTheadBased2DEntity(1, new Coordinate(250, 250, 0), 0);
	
	private RenderTestSpawner spawner;
	
	private Entity2D[] entities;
	
	/**
	 * Test per numero elevato di entita'.
	 */
	public RenderStressTest() {
		super(new StandardRender());
		
		TestMouseListener mouse = new TestMouseListener(testMob);
		addMouseMotionListener(mouse);
		
		
		spawner = new RenderTestSpawner();
		addKeyListener(spawner);
	}
	
	
	
	public void tick(Render2D renderScreen){
		
		renderScreen.cleanRenderArea();
		
		entities = spawner.cloneActalEntityBuffer();
		
		for (int i = 0; i < entities.length; i++) {
			if ( entities[i] != null) {
				renderScreen.centredRender( entities[i] );
			}
		}
		renderScreen.centredRender( testMob );
	}

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		RenderStressTest game = new RenderStressTest();
		frame.add(game);
		frame.pack();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
		frame.setResizable(false);
		frame.setLocationRelativeTo(null);
		game.start();
	}
}
